package cn.tedu.sp02.controller;

import org.springframework.web.bind.annotation.*;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * 本类用于
 *
 * @author SJXQ
 * @version 2022/1/17 13:59
 */
@RestController
@CrossOrigin
@RequestMapping("/pic")
public class ImageController {

    @GetMapping("/{imageHash}.{imageFormat}")
    public void handleImage(HttpServletResponse res, @PathVariable("imageHash") String imageHash, @PathVariable("imageFormat") String imageFormat) throws IOException {
        System.out.printf("hash:%s ,后缀:%s",imageHash,imageFormat);
        res.setContentType("image/" + imageFormat);
        ImageIO.write(ImageIO.read(new File("D:/1.jpg")), imageFormat, res.getOutputStream());
    }


}
